package com.luo.controller;

import com.alibaba.fastjson.JSON;
import com.luo.model.Goods;
import com.luo.model.Result;
import com.luo.model.recommend;
import com.luo.service.HotService;
import com.luo.util.ListTypes;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 功能：
 * 作者：Luo。
 * 日期：2024/1/9 18:03
 */
@WebServlet(urlPatterns = "/home/hot")
public class HotController extends HttpServlet {

    HotService hotService = new HotService();

    @Override
    protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
        // List<recommend> recommends = hotService.queryRecommend();
        List<Goods> recommends = hotService.queryHotGoods();
        Result result = new Result();
        result.setCode("1");
        result.setMsg("输出成功");
        result.setResult(ListTypes.getObjList(recommends));

        String jsonString = JSON.toJSONString(result);
        resp.getWriter().write(jsonString);
        resp.getWriter().close();
    }
}
